function [filelist,pathname] = jcb_pick_files(mask,disptitle,MultiSelect,directory)

if nargin<3
    MultiSelect=false;
end
if nargin<2
    disptitle='Please select a file';
end
if nargin<1
    mask='*.*';
end

if MultiSelect
    MultiSelect='on';
else
    MultiSelect='off';
end

if nargin>=4
    olddir=pwd;
    cd(directory);
end
[filelist,pathname] = uigetfile(mask,disptitle,'MultiSelect',MultiSelect);
if nargin>=4
    cd(olddir);
end

if ~iscell(filelist)
    if length(filelist)==1
        % no files were selected, so turn it into an empty array.
        filelist={};
        disp('no files selected.');
    else
        filelist={filelist};
    end
end

end